package com.xmb.wcapi;

import cn.hutool.core.date.DateTime;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.xmb.wcapi.entity.StockNowRecord;
import com.xmb.wcapi.service.*;
import com.xmb.wcapi.util.DateUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.*;

/**
 * 项目启动
 */
@Component
@Slf4j
public class StartService implements ApplicationRunner {

    @Resource
    private IStockNowRecordService recordService;

    @Value("${startTime}")
    private String startTime;

    @Override
    public void run(ApplicationArguments args) {

        //获取系统开始日期到昨天
        List<String> days = DateUtil.getEveryDayToString(DateUtil.getDateFormat(startTime), cn.hutool.core.date.DateUtil.yesterday());
        for (String day : days) {
            recordService.balanceDataNew(day);
        }

    }

}
